package com.xyzwps.server.paimon.error

import org.springframework.http.HttpStatus

enum class Errors(
    val status: HttpStatus,
    module: Int,
    codeSuffix: Int
) {
    SUCCESS(HttpStatus.OK, 0, 0),
    BAD_REQUEST(HttpStatus.BAD_REQUEST, 0, 1),
    IMPOSSIBLE(HttpStatus.INTERNAL_SERVER_ERROR, 0, 99),
    UNAUTHENTICATED(HttpStatus.UNAUTHORIZED, 0, 100),

    PHONE_HAS_BEEN_REGISTERED(HttpStatus.CONFLICT, Modules.PHONE, 1),

    VCODE_TOO_FREQUENT_60S(HttpStatus.TOO_MANY_REQUESTS, Modules.VCODE, 1),
    VCODE_TOO_FREQUENT_24H(HttpStatus.TOO_MANY_REQUESTS, Modules.VCODE, 2),
    VCODE_INVALID(HttpStatus.BAD_REQUEST, Modules.VCODE, 3),

    USER_NOT_FOUND(HttpStatus.NOT_FOUND, Modules.USER, 1),

    ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, Modules.ARTICLE, 1);

    val code: Int = module * 1000 + codeSuffix

    fun toEx(): AppException = AppException(status, code, this.name)
    fun toEx(message: String): AppException = AppException(status, code, message)
}